{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true,
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# 转置和轴滚动"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "#对换数组的维度\n",
    "import numpy as np\n",
    "a = np.arange(12).reshape(3,4)\n",
    "print ('原数组：')\n",
    "print (a )\n",
    "print ('\\n')\n",
    "\n",
    "print ('对换数组：')\n",
    "print (np.transpose(a))\n",
    "print(a)\n",
    "\n",
    "# 与transpose一致\n",
    "a = np.arange(12).reshape(3,4)\n",
    "\n",
    "print ('原数组：')\n",
    "print (a)\n",
    "print ('\\n')\n",
    "\n",
    "print ('转置数组：')\n",
    "print (a.T)\n",
    "\n",
    "# 函数用于交换数组的两个轴\n",
    "t1 = np.arange(24).reshape(4,6)\n",
    "re = t1.swapaxes(1,0)\n",
    "\n",
    "print (' 原 数 组 ：')\n",
    "print (t1)\n",
    "print ('\\n')\n",
    "print(re.shape)\n",
    "print ('调用 swapaxes 函数后的数组：')\n",
    "print (re)\n",
    "# 交换轴，到机器学习，深度学习，只要看shape\n",
    "# 从内往外\n",
    "t3=np.arange(60).reshape(3,4,5)\n",
    "print(t3)\n",
    "print('-'*50)\n",
    "t3=np.swapaxes(t3,0,2)\n",
    "print(t3.shape)\n",
    "print(t3)\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "# 轴滚动\n",
    "a = np.ones((3,4,5,6))\n",
    "np.rollaxis(a, 3,start=0).shape"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "#学会使用copy\n",
    "b=np.array([1,2,3])\n",
    "a=b.copy()\n",
    "a\n",
    "b[0]=3\n",
    "print(b)\n",
    "a"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}